package util;

import junit.framework.Assert ;
import junit.framework.TestCase ;

/**
 * @author idan
 */
public class StatisticsTest extends TestCase
{

	/**
	 * Test method for {@link util.Statistics#Statistics(int)}.
	 */
	public void testConstructor()
	{
		Statistics s = new Statistics(30) ;
		Assert.assertEquals(30, s.getQuantum()) ;
		for (int i = 0 ; i < s.getQuantum() ; i++)
		{
			Assert.assertEquals(0, s.get(i)) ;
		}
	}

	/**
	 * Test method for {@link util.Statistics#increment(int)}.
	 */
	public void testIncrement()
	{
		Statistics s = new Statistics(19) ;

		s.increment(8) ;
		Assert.assertEquals(1, s.get(8)) ;

		s.increment(0) ;
		Assert.assertEquals(1, s.get(0)) ;

		s.increment(18) ;
		Assert.assertEquals(1, s.get(18)) ;

		for (int i = 1 ; i <= 80 ; i++)
		{
			s.increment(8) ;
			Assert.assertEquals(i+1, s.get(8)) ;
		}
		Assert.assertEquals(81, s.get(8)) ;
	}

	/**
	 * Test method for {@link util.Statistics#set(int, int)}.
	 */
	public void testSet()
	{
		Statistics s = new Statistics(15) ;

		s.set(8, 3) ;
		Assert.assertEquals(3, s.get(8)) ;

		s.set(0, 4000) ;
		Assert.assertEquals(4000, s.get(0)) ;

		s.set(14, 0) ;
		Assert.assertEquals(0, s.get(14)) ;

		for (int i = 1 ; i <= 80 ; i++)
		{
			s.increment(8) ;
		}
		s.set(8, 2) ;
		Assert.assertEquals(2, s.get(8)) ;

		s.set(12, 6) ;
		for (int i = 1 ; i <= 80 ; i++)
		{
			s.increment(12) ;
		}
		Assert.assertEquals(86, s.get(12)) ;

	}

}
